package com.dycong.common.IO.calculator.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * �ͻ����߳�
 * @author yangtao__anxpp.com
 */
public class ServerWriter implements Runnable{
	private Socket socket;
	public ServerWriter(Socket socket) {
		this.socket = socket;
	}
	@Override
	public void run() {
		BufferedReader in = null;
		PrintWriter out = null;
		try{
			out = new PrintWriter(socket.getOutputStream(),true);
			in=new BufferedReader(new InputStreamReader(System.in));
			String expression;
			while(true){
				if((expression = in.readLine())==null) continue;
				out.println(expression );
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			//һЩ��Ҫ��������
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				in = null;
			}
			if(out != null){
				out.close();
				out = null;
			}
			if(socket != null){
				try {
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				socket = null;
			}
		}
	}
}